/**      
 * @file		Factorial.cpp
 * @description		This sample demonstrates how recursion is used
 *			to solve a problem. A recursive solution is a one that
 *			that calls itself to reduce a problem little by little,
 *			eventually reducing the problem to a base case that the
 *			solution knows how to solve. This example uses reuses factorial
 *			to show how recursion can be used to solve the problem of
 *			determining the factorial of some number (n). The factorial
 *			of some number is the product of:
 *
 *			f(n) = n * (n-1) * (n-2) * ... * 1 
 *					
 *			The factorial of 3 written 3! is:
 *			f(3) = 3 * (2) * (1)
 *			f(3) = 6
 *
 *			The factorial of 1 is 1 and the factorial of 
 *			(Base Case) 0 is defined as 1.
 *
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
using namespace std;

/**
 * Calculates the Factorial of some integer n.
 * @param n the number to calculate
 * @return the factorial solution of n
 * @pre n must be a non-negative integer
 * @post the factorial of n has been calculated
 */
int factorial(int aN);

/**
 * @return zero if the application executes successfully
 */
int main() {

	int n;
	cout << "Type an integer greater or equal to zero \n";
	cin >> n;

	cout << "Factorial of " << n << " is " << factorial(n);

	/*
	* This can be solved iteratively by writing a loop.
	*
	int result = 1;
	for(int i = n; i >= 1; i--) {
	  result *= i;
	}

	What's the advantage to providing a recursive solution?
	What's the disadvantage?
	*/

	return 0;
}

int factorial(int aN) {
	if (aN == 0) { // Base Case
		return 1;
	} else {
		return aN * factorial(aN - 1); // Recursive call
	}
}
